local hx__xufa_active = fk.CreateSkill {
  name = "hx__xufa_active",
}

Fk:loadTranslationTable{
  ["hx__xufa_active"] = "蓄发",
}

hx__xufa_active:addEffect("active", {
  expand_pile = "hx__xufa",
  min_card_num = function(self, player)
    if player:getSwitchSkillState("hx__xufa", true) == fk.SwitchYang then
      return math.max((player:getHandcardNum() + 1) // 2, 1)
    end
    return math.max((#player:getPile("hx__xufa") + 1) // 2, 1)
  end,
  -- min_card_num = 1,
  target_num = 0,
  card_filter = function(self, player, to_select, selected)
    if player:getSwitchSkillState("hx__xufa", true) == fk.SwitchYang then
      return table.contains(player:getCardIds("h"), to_select)
    else
      return table.contains(player:getPile("hx__xufa"), to_select)
    end
  end,
  feasible = function (self, player, selected, selected_cards, card)
    if player:getSwitchSkillState("hx__xufa", true) == fk.SwitchYang then
      return #selected == 0 and #selected_cards >= math.max((player:getHandcardNum() + 1) // 2, 1) and
      table.find(selected_cards, function (id) return Fk:getCardById(id):getMark("hx__xufa-inhand") > 0 end)
    else
      return #selected == 0 and #selected_cards >= math.max((#player:getPile("hx__xufa") + 1) // 2, 1) and
      table.find(selected_cards, function (id) return Fk:getCardById(id):getMark("hx__xufa-inhand") > 0  end)
    end
  end,
})

return hx__xufa_active
